package edu.pitt.cs.cs2410pj2.core;

import java.io.IOException;
import java.util.ArrayList;

import edu.pitt.cs.cs2410pj2.util.ParameterReader;
import edu.pitt.cs.cs2410pj2.util.Parameters;
import edu.pitt.cs.cs2410pj2.util.TheLogger;
import edu.pitt.cs.cs2410pj2.util.Trace;
import edu.pitt.cs.cs2410pj2.util.TraceReader;

/**
 * The main program
 * @author zhangfan
 *
 */
public class MainProgram {
	public static void main(String[] args) throws IOException {
		//Get parameters
		boolean isDebug = false;
		String tracesFile = "";
		String configFile = "";
		tracesFile = args[1];
		configFile = args[0];
		if(args.length>2) isDebug = true;
//		tracesFile = "traces.txt";
//		configFile = "config.txt";
		
		
		//Setup CMP
		TheLogger logger = new TheLogger();
		ArrayList<Trace> traces = TraceReader.readTraces(tracesFile);
		Parameters para = ParameterReader.loadParameters(configFile);
		if(isDebug) {
			para = ParameterReader.getDebugPara();
			traces = TraceReader.readTraces("shortTrace.txt");
		}
		
		//Run and print out traces
		CMP cmp = new CMP(para);
		cmp.setLogger(logger);
		cmp.addTraces(traces);
		try {
			cmp.run(isDebug);
		} catch(Exception exp) {
			exp.printStackTrace();
			logger.log(exp.getMessage());
		}finally {
			logger.closeLogger();
		}
	}
}
